#include "CSCodec.h"
//////////////////////////////////////////////////////////////////////////
CSCodec::CSCodec()
{

}

CSCodec::~CSCodec()
{

}

RawPacket* CSCodec::PacketDecode(const void* buffer, uint32_t size)
{
	RawPacket* pPacket = new RawPacket;
	memset(pPacket, 0x00, sizeof(*pPacket));
	
	pPacket->buffer = new char[size];
	pPacket->length = size;
	pPacket->buffer_length = size;
	pPacket->cmd = 1;

	memcpy(pPacket->buffer, buffer, size);

	return pPacket;
}

SendBuffer* CSCodec::PacketEncode(const void* buffer, uint32_t size, CONTENT_TYPE type)
{
	SendBuffer* pSendBuffer = new SendBuffer;
	memset(pSendBuffer, 0x00, sizeof(*pSendBuffer));
	pSendBuffer->buffer = new char[size];
	pSendBuffer->length = size;
	memcpy(pSendBuffer->buffer, buffer, size);

	return pSendBuffer;
}

void CSCodec::DeleteRawPacket(RawPacket * packet)
{
	if (packet)
	{
		if (packet->buffer)
		{
			delete[]packet->buffer;
		}
		delete packet;
	}
}

void CSCodec::DeleteSendBuffer(SendBuffer * sendBuffer)
{
	if (sendBuffer)
	{
		if (sendBuffer->buffer)
		{
			delete[]sendBuffer->buffer;
		}
		delete sendBuffer;
	}
}
